<template>
  <div class="login-container">
    <div class="login-card">
      <div class="login-left">
        <el-image :src="img" class="login-image" fit="cover"></el-image>
      </div>
      <div class="login-right">
        <h2 class="login-title">欢迎登录</h2>
        <el-form label-width="100px" class="login-form">
          <el-form-item label="用户名">
            <el-input 
              size="large" 
              v-model="custmer.username" 
              placeholder="请输入用户名"
              prefix-icon="User"
              clearable
            />
          </el-form-item>
          <el-form-item label="密码">
            <el-input 
              size="large" 
              v-model="custmer.password" 
              show-password 
              placeholder="请输入密码"
              prefix-icon="Lock"
            />
          </el-form-item> 
          <el-form-item class="login-buttons">
            <el-button 
              type="primary" 
              @click="doLogin" 
              class="login-button"
              round
            >登录</el-button>
            <el-button 
              type="success" 
              @click="register"
              class="register-button"
              round
            >注册</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
// 脚本保持不变
import axios from 'axios';
import img from '@/assets/images/userindex.png'
import {store} from '@/common/store'
import { ref, reactive } from "vue"
import { ElMessage } from 'element-plus';
import { useRouter } from 'vue-router'
const custmer = reactive({ username: "", password: ""}) 
const router = useRouter() 

function doLogin() {
  axios.post("/public/login", custmer).then(res => {
     console.log(res.data)
     if(res.data.code*1==200){
        store.logined = true;
        store.userinfo={id:res.data.data.id,username:res.data.data.username,name:res.data.data.name,address:res.data.data.address}
        store.token = res.data.data.token
        sessionStorage.setItem("token",store.token)
        sessionStorage.setItem("userinfo",JSON.stringify(store.userinfo))
        ElMessage.success("登陆成功")
        router.push("/products")
     }else{        
        ElMessage.error(res.data.message)        
     }
  })
} 

function register() {
  router.push("/register");
}
</script> 

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 20px;
}

.login-card {
  display: flex;
  width: 900px;
  height: 500px;
  background: white;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.login-left {
  flex: 1;
  background: linear-gradient(135deg, #4b6cb7 0%, #182848 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
}

.login-image {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  object-fit: cover;
}

.login-right {
  flex: 1;
  padding: 40px 30px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-title {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 30px;
  font-size: 28px;
  font-weight: 600;
}

.login-form {
  width: 100%;
}

.login-buttons {
  margin-top: 30px;
  display: flex;
  justify-content: center;
}

.login-button {
  width: 120px;
  height: 45px;
  font-size: 16px;
  margin-right: 20px;
}

.register-button {
  width: 120px;
  height: 45px;
  font-size: 16px;
}

:deep(.el-form-item__label) {
  font-weight: 600;
  color: #34495e;
}

@media (max-width: 768px) {
  .login-card {
    flex-direction: column;
    height: auto;
  }
  
  .login-left {
    height: 250px;
  }
}
</style>